package gui2.g4;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Painting extends JComponent {

	static int x = 5;
	static int y = 5;

	{
		setPreferredSize(new Dimension(500, 500));
	}

	@Override
	protected void paintComponent(Graphics g) {
		//super.paintComponent(g);

		Graphics2D g2 = (Graphics2D) g;

		g.setColor(Color.BLUE);
		g.drawRect(5, 5, 100, 200);

		g.setColor(new Color(255, 255, 0, 100));
		g.fillOval(x, y, 120, 120);
	}

	public static void main(String[] args) {
		
		final Painting p = new Painting();
		
		JFrame f = new JFrame();
		f.getContentPane().add(p);
		f.pack();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
		
		new Thread(){
			public void run() {
				while(x<500 && y <500){
					x+=5;
					y+=5;
					try {
						Thread.sleep(200);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
					p.repaint();
				}
			};
		}.start();
		
	}
}
